from api.ihrm_dep_api import IhrmDepApi
from api.ihrm_login_api import IhrmLoginApi
from common.assert_tooles import common_assert


class TestDep(object):
    token = None
    dep_id = None

    def setup_class(self):
        data = {"mobile": "13800000002", "password": "123456"}
        resp = IhrmLoginApi.login(data)
        self.token = resp.json().get("data")

        req_header = {"Authorization": f"{self.token}"}
        req_data = {"name": "七七七七", "code": "9527777"}
        resp1 = IhrmDepApi.add_dep(req_header, req_data)
        self.dep_id = resp1.json().get("data").get("id")


    def test01_add_dep(self):
        req_header = {"Authorization": f"{self.token}"}
        req_data = {"name": "至尊宝七七七七", "code": "9527676767"}
        resp = IhrmDepApi.add_dep(req_header, req_data)
        print("添加部门: ", resp.json())
        common_assert(resp, 200, True, 10000, "操作成功")

    def test02_query_dep(self):
        dep_id = "1495045644891496448"
        req_header = {"Authorization": f"{self.token}"}
        resp = IhrmDepApi.query_dep(dep_id, req_header)
        print("查询部门: ", resp.json())
        common_assert(resp, 200, True, 10000, "操作成功")

    def test03_modify_dep(self):
        dep_id = "1495045723828297728"
        req_header = {"Authorization": f"{self.token}"}
        req_data = {"name": "至尊宝阿aaa", "code": "9527676767"}
        resp = IhrmDepApi.modify_dep(dep_id, req_header, req_data)
        print("修改部门: ", resp.json())
        common_assert(resp, 200, True, 10000, "操作成功")

    def test04_delete_dep(self):
        dep_id = f"{self.dep_id}"
        req_header = {"Authorization": f"{self.token}"}
        resp = IhrmDepApi.delete_dep(dep_id, req_header)
        print("删除部门: ", resp.json())
        common_assert(resp, 200, True, 10000, "操作成功")
